{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "material-professor",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "   <div id=\"dETTlL\"></div>\n",
       "   <script type=\"text/javascript\" data-lets-plot-script=\"library\">\n",
       "       if(!window.letsPlotCallQueue) {\n",
       "           window.letsPlotCallQueue = [];\n",
       "       }; \n",
       "       window.letsPlotCall = function(f) {\n",
       "           window.letsPlotCallQueue.push(f);\n",
       "       };\n",
       "       (function() {\n",
       "           var script = document.createElement(\"script\");\n",
       "           script.type = \"text/javascript\";\n",
       "           script.src = \"https://cdn.jsdelivr.net/gh/JetBrains/lets-plot@v2.4.0/js-package/distr/lets-plot.min.js\";\n",
       "           script.onload = function() {\n",
       "               window.letsPlotCall = function(f) {f();};\n",
       "               window.letsPlotCallQueue.forEach(function(f) {f();});\n",
       "               window.letsPlotCallQueue = [];\n",
       "               \n",
       "               \n",
       "           };\n",
       "           script.onerror = function(event) {\n",
       "               window.letsPlotCall = function(f) {};\n",
       "               window.letsPlotCallQueue = [];\n",
       "               var div = document.createElement(\"div\");\n",
       "               div.style.color = 'darkred';\n",
       "               div.textContent = 'Error loading Lets-Plot JS';\n",
       "               document.getElementById(\"dETTlL\").appendChild(div);\n",
       "           };\n",
       "           var e = document.getElementById(\"dETTlL\");\n",
       "           e.appendChild(script);\n",
       "       })();\n",
       "   </script>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "%useLatestDescriptors\n",
    "%use lets-plot\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "going-administration",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "   <div id=\"7nZVJx\"></div>\n",
       "   <script type=\"text/javascript\" data-lets-plot-script=\"plot\">\n",
       "       (function() {\n",
       "           var plotSpec={\n",
       "\"ggtitle\":{\n",
       "\"text\":\"The plot title\",\n",
       "\"subtitle\":\"The plot subtitle\"\n",
       "},\n",
       "\"mapping\":{\n",
       "},\n",
       "\"data\":{\n",
       "\"x\":[0.0,1.0,2.0,3.0,4.0],\n",
       "\"y\":[0.0,1.0,2.0,3.0,4.0]\n",
       "},\n",
       "\"kind\":\"plot\",\n",
       "\"scales\":[{\n",
       "\"aesthetic\":\"x\",\n",
       "\"name\":\"X axis title\"\n",
       "},{\n",
       "\"aesthetic\":\"y\",\n",
       "\"name\":\"Y axis title\"\n",
       "},{\n",
       "\"aesthetic\":\"color\",\n",
       "\"name\":\"Color legend title\"\n",
       "},{\n",
       "\"aesthetic\":\"size\",\n",
       "\"name\":\"Size legend title\"\n",
       "}],\n",
       "\"layers\":[{\n",
       "\"mapping\":{\n",
       "\"x\":\"x\",\n",
       "\"y\":\"y\",\n",
       "\"color\":\"y\",\n",
       "\"size\":\"y\"\n",
       "},\n",
       "\"stat\":\"identity\",\n",
       "\"position\":\"identity\",\n",
       "\"geom\":\"point\",\n",
       "\"tooltips\":{\n",
       "\"tooltip_lines\":[\"label|value\"],\n",
       "\"tooltip_title\":\"TITLE\"\n",
       "},\n",
       "\"data\":{\n",
       "}\n",
       "}],\n",
       "\"caption\":{\n",
       "\"text\":\"The plot caption\"\n",
       "}\n",
       "};\n",
       "           var plotContainer = document.getElementById(\"7nZVJx\");\n",
       "           window.letsPlotCall(function() {{\n",
       "               LetsPlot.buildPlotFromProcessedSpecs(plotSpec, -1, -1, plotContainer);\n",
       "           }});\n",
       "       })();    \n",
       "   </script>"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "// default theme\n",
    "val dat = mapOf(\"x\" to 0..4, \"y\" to 0..4)\n",
    "val p = letsPlot(dat) +\n",
    "        geomPoint(tooltips = layerTooltips().title(\"TITLE\").line(\"label|value\")) {\n",
    "            x = \"x\"\n",
    "            y = \"y\"\n",
    "            size = \"y\"\n",
    "            color = \"y\"\n",
    "        } +\n",
    "        labs(title = \"The plot title\", \n",
    "         subtitle = \"The plot subtitle\",\n",
    "         caption = \"The plot caption\",\n",
    "         x = \"X axis title\", \n",
    "         y = \"Y axis title\", \n",
    "         color = \"Color legend title\",\n",
    "         size = \"Size legend title\"\n",
    "    )\n",
    "p"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "olympic-michael",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "   <div id=\"XBpOQX\"></div>\n",
       "   <script type=\"text/javascript\" data-lets-plot-script=\"plot\">\n",
       "       (function() {\n",
       "           var plotSpec={\n",
       "\"ggtitle\":{\n",
       "\"text\":\"The plot title\",\n",
       "\"subtitle\":\"The plot subtitle\"\n",
       "},\n",
       "\"mapping\":{\n",
       "},\n",
       "\"data\":{\n",
       "\"x\":[0.0,1.0,2.0,3.0,4.0],\n",
       "\"y\":[0.0,1.0,2.0,3.0,4.0]\n",
       "},\n",
       "\"kind\":\"plot\",\n",
       "\"scales\":[{\n",
       "\"aesthetic\":\"x\",\n",
       "\"name\":\"X axis title\"\n",
       "},{\n",
       "\"aesthetic\":\"y\",\n",
       "\"name\":\"Y axis title\"\n",
       "},{\n",
       "\"aesthetic\":\"color\",\n",
       "\"name\":\"Color legend title\"\n",
       "},{\n",
       "\"aesthetic\":\"size\",\n",
       "\"name\":\"Size legend title\"\n",
       "}],\n",
       "\"layers\":[{\n",
       "\"mapping\":{\n",
       "\"x\":\"x\",\n",
       "\"y\":\"y\",\n",
       "\"color\":\"y\",\n",
       "\"size\":\"y\"\n",
       "},\n",
       "\"stat\":\"identity\",\n",
       "\"position\":\"identity\",\n",
       "\"geom\":\"point\",\n",
       "\"tooltips\":{\n",
       "\"tooltip_lines\":[\"label|value\"],\n",
       "\"tooltip_title\":\"TITLE\"\n",
       "},\n",
       "\"data\":{\n",
       "}\n",
       "}],\n",
       "\"caption\":{\n",
       "\"text\":\"The plot caption\"\n",
       "},\n",
       "\"theme\":{\n",
       "\"plot_caption\":{\n",
       "\"face\":\"italic\",\n",
       "\"blank\":false\n",
       "},\n",
       "\"legend_text\":{\n",
       "\"face\":\"italic\",\n",
       "\"blank\":false\n",
       "},\n",
       "\"axis_title\":{\n",
       "\"face\":\"bold\",\n",
       "\"blank\":false\n",
       "},\n",
       "\"axis_text\":{\n",
       "\"face\":\"bold_italic\",\n",
       "\"blank\":false\n",
       "},\n",
       "\"plot_title\":{\n",
       "\"face\":\"italic\",\n",
       "\"blank\":false\n",
       "},\n",
       "\"tooltip_text\":{\n",
       "\"face\":\"italic\",\n",
       "\"blank\":false\n",
       "},\n",
       "\"legend_title\":{\n",
       "\"face\":\"bold\",\n",
       "\"blank\":false\n",
       "},\n",
       "\"plot_subtitle\":{\n",
       "\"face\":\"bold_italic\",\n",
       "\"blank\":false\n",
       "}\n",
       "}\n",
       "};\n",
       "           var plotContainer = document.getElementById(\"XBpOQX\");\n",
       "           window.letsPlotCall(function() {{\n",
       "               LetsPlot.buildPlotFromProcessedSpecs(plotSpec, -1, -1, plotContainer);\n",
       "           }});\n",
       "       })();    \n",
       "   </script>"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "// Change the font face property of some elements.\n",
    "\n",
    "p + theme(\n",
    "        plotTitle = elementText(face = \"italic\"), \n",
    "        plotSubtitle = elementText(face = \"bold_italic\"),\n",
    "        plotCaption = elementText(face = \"italic\"),\n",
    "    \n",
    "        legendTitle = elementText(face = \"bold\"),\n",
    "        legendText = elementText(face = \"italic\"),\n",
    "    \n",
    "        axisTitle = elementText(face = \"bold\"),\n",
    "        axisText = elementText(face = \"bold_italic\"),\n",
    "\n",
    "        // The 'tooltipText' value will also applied to axes tooltips ('italic');\n",
    "        // title and label in general tooltip are bold by default -> the result for them is 'bold_italic' \n",
    "        tooltipText = elementText(face = \"italic\"))\n"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Kotlin",
   "language": "kotlin",
   "name": "kotlin"
  },
  "language_info": {
   "codemirror_mode": "text/x-kotlin",
   "file_extension": ".kt",
   "mimetype": "text/x-kotlin",
   "name": "kotlin",
   "nbconvert_exporter": "",
   "pygments_lexer": "kotlin",
   "version": "1.7.20-dev-1299"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
